﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace Minestorm.Retro.GameLogic
{
    public class SoundManager
    {
        private Dictionary<string, SoundEffect> _soundEffects;

        public SoundManager()
        {
            _soundEffects = new Dictionary<string, SoundEffect>();
            _soundEffects.Add("intro_sound", null);
            _soundEffects.Add("spawn_sound", null);
            _soundEffects.Add("explode_sound", null);
            _soundEffects.Add("fire_sound", null);
            _soundEffects.Add("thrust_sound", null);
            _soundEffects.Add("thrustend_sound", null);
        }

        public void LoadContent(ContentManager content)
        {
            foreach (var name in _soundEffects.Keys.ToArray())
                _soundEffects[name] = content.Load<SoundEffect>("Retro\\Audio\\" + name);
        }

        public void UnloadContent()
        {
            foreach (var name in _soundEffects.Keys.ToArray())
            {
                _soundEffects[name].Dispose();
                _soundEffects[name] = null;
            }
        }

        public SoundEffect GetSoundEffect(string name)
        {
            return _soundEffects[name];
        }

        public void Play(string name)
        {
            GetSoundEffect(name).Play();
        }

        //public void Pause()
        //{
        //    if (_isPaused) return;
        //    foreach (var soundEffect in _soundEffects.Values)
        //        if (soundEffect.State == SoundState.Playing)
        //            soundEffect.Pause();
        //    _isPaused = true;
        //}
        //public void Resume()
        //{
        //    if (!_isPaused) return;
        //    foreach (var soundEffect in _soundEffects.Values)
        //        if (soundEffect.State == SoundState.Paused)
        //            soundEffect.Resume();
        //    _isPaused = false;
        //}
    }

    public class TextureManager
    {
        private Dictionary<string, Texture2D> _textures;

        public TextureManager()
        {
            _textures = new Dictionary<string, Texture2D>();
            _textures.Add("star", null);
            _textures.Add("bullet", null);
            _textures.Add("pointsprite", null);
            _textures.Add("gameplay_bg", null);
        }

        public void LoadContent(ContentManager content)
        {
            foreach (var name in _textures.Keys.ToArray())
                _textures[name] = content.Load<Texture2D>("Retro\\" + name);
        }

        public void UnloadContent()
        {
            foreach (var name in _textures.Keys.ToArray())
            {
                _textures[name].Dispose();
                _textures[name] = null;
            }
        }

        public Texture2D GetTexture(string name)
        {
            return _textures[name];
        }
    }
}
